﻿
<table id="dgRole"></table>
<div id="dlgAddRole" class="easyui-dialog" style="width: 500px; height: 140px; padding: 10px 20px"
     closed="true" buttons="#dlgAddRole-buttons">
    @Html.Partial("_Create")
    <div id="dlgAddRole-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick=" saveRole() " style="width: 90px">ذخیره</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick=" javascript: $('#dlgAddRole').dialog('close'); " style="width: 90px">انصراف</a>
    </div>
</div>

@*<div id="dlgEditRole" class="easyui-dialog" style="width: 500px; height: 140px; padding: 10px 20px"
     closed="true" buttons="#dlgEditRole-buttons">
</div>
<div id="dlgEditRole-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6 " iconcls="icon-ok" onclick=" updateRole() " style="width: 90px">ذخیره</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick=" javascript: $('#dlgEditRole').dialog('close'); " style="width: 90px">انصراف</a>
</div>*@
@section scripts{
    @*@Scripts.Render("/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryAjaxForm")*@

<script src="~/Content/jquery-easyui-1.4.2/edatagrid.js"></script>
    <script>
        //$('#frmAddRole').ajaxForm();

        $('#dgRole').edatagrid(
       {
           toolbar:
           [
               {
                   text: 'جدید',
                   iconCls: 'icon-add',
                   handler: function () {
                       $('#dgRole').edatagrid('addRow');
                   }
               }, '-',
               {
                   text: 'حذف',
                   iconCls: 'icon-remove',
                   handler: function () {
                       $('#dgRole').edatagrid('destroyRow');
                   }
               }, '-',
               {
                   text: 'ذخیره',
                   iconCls: 'icon-save',
                   handler: function () {
                       $('#dgRole').edatagrid('saveRow');
                   }
               }, '-',
               {
                   text: 'انصراف',
                   iconCls: 'icon-undo',
                   handler: function () {
                       $('#dgRole').edatagrid('cancelRow');
                   }
               }
           ],
           fit: true,
           idField: 'Id',
           title: 'لیست مراحل',
           loadMsg: 'شکیبا باشید...',
           rownumbers: true,
           height: '480',
           singleSelect: 'true',
           fitColumns: 'true',
           url: '@Url.Action("GetRoles", "RolesAdmin")',
           saveUrl: '@Url.Action("Create", "RolesAdmin")',
           updateUrl: '@Url.Action("Edit", "RolesAdmin")',
           destroyUrl: '@Url.Action("Delete", "RolesAdmin")',
           onError: function (index, row) {
           },
           onSuccess: function(index, row) {
               $.messager.show({
                   title: 'پیام سیستم',
                   msg: result.Msg,
                   showType: 'show'
               });
           },
           columns: [
               [
                   { field: 'Id', width: 300,hidden:'hidden', editor: { type: 'validatebox',width: 300 } },

                    { field: 'Name', title: 'نام لاتین', width: 300, editor: { type: 'validatebox', width: 300, options: { required: true } } },
                    { field: 'PersianName', title: 'نام فارسی', width: 300, editor: { type: 'validatebox', width: 300, options: { required: true } } }  
               ]
           ]
       });

        @*$('#dgRole').datagrid(
        {
            toolbar:
            [
                {
                    text: 'جدید',
                    iconCls: 'icon-add',
                    handler: function() {
                        $('#dlgAddRole').dialog('open').dialog('setTitle', 'تعریف نقش');
                    }
                }, '-',
                {
                    text: 'جستجو',
                    iconCls: 'icon-search',
                    handler: function() {
                        $.messager.alert("Action", "Search");
                    }
                }, '-',
                {
                    text: 'راهنما',
                    iconCls: 'icon-help',
                    handler: function() {
                        $.messager.alert("Action", "Help");
                    }
                }
            ],
            fit:true,
            title: 'لیست نقش ها',
            loadMsg: 'شکیبا باشید...',
            rownumbers: true,
            height: '480',
            singleSelect: 'true',
            sortName: 'Name',
            sortOrder: 'asc',
            pagination: true,
            pagePosition: 'bottom',
            striped: 'true',
            fitColumns: 'true',
            pageSize: 10,
            url: '@Url.Action("GetRoles", "RolesAdmin", new {area = "UserArea"})',
            columns: [
                [
                    { field: 'Name', title: 'نام', width: 300 },
                    {
                        field: 'Action',
                        title: 'عملیات',
                        width: 100,
                        formatter: function(value, rows, index) {
                            return '<a roleId=' + rows.Id + ' href="javascript:void(0)"  onclick="destroyRole(this)"><img class="delete"  src="/content/jquery-easyui-1.4.2/themes/icons/cancel.png"/></a>&nbsp&nbsp&nbsp' +
                                '<a roleId=' + rows.Id + ' href="javascript:void(0)" onclick="showdlgRoleEdit(this)"><img src="/content/jquery-easyui-1.4.2/themes/icons/pencil.png" title="ویرایش"/></a>';
                        }
                    }
                ]
            ]
        });*@

        //var pager = $('#dgRole').datagrid('getPager');
        //$(pager).pagination({
        //    pageSize: 10,
        //    showPageList: true,
        //    pageList: [10, 20, 50],
        //    beforePageText: 'صفحه',
        //    afterPageText: 'از {pages}',
        //    displayMsg: 'نمایش اطلاعات  {from} تا {to} از {total}'
        //});

        @*function saveRole() {
            if ($('#frmAddRole').valid()) {
                $('#frmAddRole').ajaxSubmit({
                    cashe: false,
                    url: '@Url.Action("Create", "RolesAdmin", new {area = "UserArea"}, "http")',
                    type: 'Post',
                    dataType: 'json',
                    data: $('#frmAddRole').serialize(),
                    success: function(result) {
                        $('#frmAddRole').form('clear');
                        $('#dgRole').datagrid('reload');
                        $.messager.show({
                            title: 'پیام سیستم',
                            msg: result.Msg,
                            showType: 'show'
                        });
                    },
                    error: function(xhr, status) {
                        xhr.responseText();
                    }
                });
            } else {
                return $(this).form('validate');
            }
        }

        function destroyRole(element) {
            $.messager.confirm('confirm', 'حذف شود؟', function(r) {
                if (r) {
                    $.post('@Url.Action("Delete", "RolesAdmin", new {area = "UserArea"}, "http")', { id: $(element).attr('roleId') }, function(result) {
                        if (result.success) {
                            $.messager.show({
                                title: 'پیام سیستم',
                                msg: result.Msg,
                                showType: 'show'
                            });
                            $('#dgRole').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'پیام سیستم',
                                msg: result.Msg,
                                showType: 'show'
                            });
                        }
                    }, 'json');
                }
            });
        }

        function showdlgRoleEdit(element) {
            $.ajax({
                url: '@Url.Action("Edit", "RolesAdmin", new {area = "UserArea"})',
                dataType: 'html',
                type: 'get',
                data: {roleId: $(element).attr('roleId')},
                success: function(result) {
                    $('#dlgEditRole').html(result);
                    $('#dlgEditRole').dialog('open').dialog('setTitle', 'ویرایش نقش');
                },
                error: function() {

                }
            });
        }


        function updateRole() {
            if ($('#frmEditRole').valid()) {
                $('#frmEditRole').ajaxSubmit({
                    cashe: false,
                    url: '@Url.Action("Edit", "RolesAdmin", new {area = "UserArea"}, "http")',
                    type: 'Post',
                    dataType: 'json',
                    data: $('#frmEditRole').serialize(),
                    success: function(result) {
                        $('#frmEditRole').form('clear');
                        $('#dgRole').datagrid('reload');
                        $.messager.show({
                            title: 'پیام سیستم',
                            msg: result.Msg,
                            showType: 'show'
                        });
                    },
                    error: function(xhr, status) {
                        xhr.responseText();
                    }
                });
            } else {
                return $(this).form('validate');
            }
        }*@
    </script>
}